<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
    <title>登录</title>
    <link href="../css.min/mui.min.css" rel="stylesheet"/>
    <link rel="stylesheet" href="../css/header.css" />
    <link rel="stylesheet" href="../css/common.css" />
</head>
<body>
	<header class="mui-bar mui-bar-nav">
	    <a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left"></a>
	    <h1 class="mui-title">用户登录</h1>
	</header>
	<div class="mui-content">
		<div class="mui-content-padded" style="margin: 20px;"> 
			<div class="mui-input-group"> 
				<div class="mui-input-row"> 
					<input id="user-name" type="text" placeholder="输入用户名"> 
				</div> 
				<div class="mui-input-row" style="margin-top: -1px;"> 
					<input id="user-password" type="password" placeholder="请输入密码"> 
				</div> 
			</div>  
			<div class="mui-button-row" style="margin-bottom: 40px;margin-top: 20px;"> 
				<button id="user-login" type="button" class="mui-btn mui-btn-primary mui-btn-block" style="padding:6px 0;background-color: #EE4B62;border: 1px #EE4B62;" onclick="return false;">登录</button> 
			</div> 
		</div>
	</div>
</body>
<script src="../js.min/mui.min.js"></script>
<script type="text/javascript" src="../js/config.js" ></script>
<script type="text/javascript" src="../js/utils.js" ></script>
<script type="text/javascript" src="../js/cache.js" ></script>
<script type="text/javascript" charset="utf-8">
    mui.init();
    
    var Name_Input=null,Password_Input=null,Login_Btn=null;
    document.addEventListener("DOMContentLoaded",function(){
    	Name_Input=document.getElementById("user-name");
    	Password_Input=document.getElementById("user-password");
    	Login_Btn=document.getElementById("user-login");
    	
    	//登录
    	Login_Btn.addEventListener('tap',function(){
    		var e=this;
    		e.userName=Name_Input.value;
    		var password=Password_Input.value;
    		
    		if(e.userName.length<1) return mui.toast("请输入用户名");
    		if(password.length<1) return mui.toast("请输入用户密码");
    		
    		e.wa=plus.nativeUI.showWaiting("玩命登录中...");
    		
    		mui.ajax_query("userLogin!PPH",{"userName":e.userName.trim(),
    			"password":password.trim()},function(d){
    			
    			if(!d){
    				e.wa.close();
    				mui.toast("用户名或密码错误");
    				return;
    			}
    			
    			CACHE.Login("true");
    			CACHE.UserName(e.userName);
    			
    			//页面所有者实现
    			e.ownerView=plus.webview.currentWebview().opener();
    			mui.fire(e.ownerView,"RefreshPage");
    			
    			//可能刷新订单中心webview
    			e.orderView=plus.webview.getWebviewById("pages/order.html");
    			if(e.orderView) mui.fire(e.orderView,"RefreshPage");
    			
    			//可能刷新个人中心页面
    			e.personView=plus.webview.getWebviewById("pages/person.html");
    			if(e.personView) mui.fire(e.personView,"RefreshPage");
    			
    			setTimeout(function(){
    				e.wa.close();
    				plus.webview.currentWebview().close();
    			},1000);
    			
    		},function(c,m){
    			e.wa.close();
    			mui.alert("登录失败");
    		});
    		
    	});
    	
    },false);
    
    /**
     * h5+ ready
     */
    mui.plusReady(function(){
    	if(CACHE.Login()=="true"){
    		Name_Input.value=CACHE.UserName()||"";
    	}
    });
    
</script>
</html>